/**   
 * @Title: UserController.java 
 * @Package org.playgod1984.du.auth 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author playgod playgod1984@163.com  
 * @date 2014年10月15日 上午11:22:26 
 * @version V1.0   
 */
package org.playgod1984.du.auth.controller;

import java.util.Map;

import org.playgod1984.du.auth.model.User;
import org.playgod1984.du.auth.validator.UserValidator;
import org.playgod1984.du.base.ApplicationController;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Page;

/** 
 * @ClassName: UserController 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author playgod playgod1984@163.com 
 * @date 2014年10月15日 上午11:22:26 
 *  
 */
@SuppressWarnings("all")
public class UserController extends ApplicationController {
	
	/**
	 * @Title: login
	 * @author:playgod playgod1984@163.com 
	 * @Description: 登陆 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void login(){
		User user = User.dao.findById("playgod1984");
		getSession().setAttribute("currentUser", user);
		render("/WEB-INF/views/ddesign/main.html");
	}
	/**
	 * @Title: list
	 * @author:playgod playgod1984@163.com 
	 * @Description: User List for request /auth/user/list 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void list(){
		// direct to user_list.html
		render("/WEB-INF/views/auth/user/user_list.html");
	}
	/**
	 * @Title: pagenate
	 * @author:playgod playgod1984@163.com 
	 * @Description: page query
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void pagenate(){
		Map params = getParamsMap();// get
		// Query All Users
		User um = getModel(User.class);
		Page<User> userList = um.getUsersWithPagenate(params);
		//Map whereMap = getDataGridFilter();
		renderJson("Rows", userList.getList());
	}
	/**
	 * @Title: g2add
	 * @author:playgod playgod1984@163.com 
	 * @Description: To Add
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void g2add(){
		setAttr("screen", "A");// update
		render("/WEB-INF/views/auth/user/user_edit.html");
	}
	
	/**
	 * @Title: g2edit
	 * @author:playgod playgod1984@163.com 
	 * @Description: ADD,EDIT,VIEW USER
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void g2edit(){
		User user = User.dao.findById(getPara("loginaccount"));
		setAttr("user", user);
		setAttr("screen", "E");// update
		render("/WEB-INF/views/auth/user/user_edit.html");
	}
	/**
	 * @Title: save
	 * @author:playgod playgod1984@163.com 
	 * @Description: save user
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	@Before(UserValidator.class)
	public void save(){
		Map params = getParamsMap();
		if(User.dao.save(params)){
			renderJson(RES_SUCCESS);
		}else{
			renderJson(RES_FAILED);
		}
	}
	/**
	 * @Title: delete
	 * @author:playgod playgod1984@163.com 
	 * @Description: Delete Records
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void delete(){
		Map params = getParamsMap();
		int delRes = User.dao.deleteRows(params);
		renderJson(delRes);
	}
}
